package com.example.springdemo.service.user.impl;

import com.example.springdemo.dao.user.UserMapper;
import com.example.springdemo.datasource.DB;
import com.example.springdemo.datasource.DataSource;
import com.example.springdemo.datasource.DataSourceContextHolder;
import com.example.springdemo.domain.entity.user.User;
import com.example.springdemo.service.user.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wanghuajun
 * @version 1.0
 * @date 2019-08-09 21:21
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @DataSource(name = DB.USER_CENTER)
    @Override
    public User getUserById(Integer id) {
        log.info("UserServiceImpl#getUserById数据源为---------------->dataSource:{}", DataSourceContextHolder.getDataSourceType());

        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateUser(User user) {

        log.info("执行updateUser方法");

        return userMapper.updateByPrimaryKeySelective(user);
    }
}
